<?
require_once("mvc/action/Action.php");
require_once("cms/project/om/ProjectI18nPeer.php");

class EditAction extends Action {

    private $log;

    public function __construct() {
        $this->log =& LoggerManager::getLogger("EditAction");
    }

    public function execute(ActionConfig &$mapping, &$form, Request &$request, Response &$response) {

        if($form->getProjectI18n()->getProjectI18nId() > 0) {

            $projectI18n = ProjectI18nPeer::retrieveByPk($form->getProjectI18n()->getProjectI18nId());
            if(!is_null($projectI18n)) {

                $form->setProjectI18n($projectI18n);

                $form->setDay($projectI18n->getProject()->getDate("d"));
                $form->setMonth($projectI18n->getProject()->getDate("m"));
                $form->setYear($projectI18n->getProject()->getDate("Y"));

            } else {
                $this->log->error("No projectI18n found with id {$form->getProjectI18n()->getProjectI18nId()}.");
                $form->getProjectI18n()->setProjectI18nId("");

                if($form->getProjectI18n()->getLanguageCode() === null)
                    $form->getProjectI18n()->setLanguageCode(
                        $request->getContext()->getInitParameter(_Core::DEFAULT_LANGUAGE)
                    );
            }

        } else if($form->getProjectI18n()->getProjectId() > 0) {

            $project = ProjectPeer::retrieveByPk($form->getProjectI18n()->getProjectId());
            if(!is_null($project)) {
                $form->getProjectI18n()->setProject($project);
            } else {
                $this->log->error("No projectI18n found with id ".$form->getProjectI18n()->getProjectI18nId().".");
                $form->getProjectI18n()->setProjectI18nId("");
            }

        } else {

            if($form->getProjectI18n()->getLanguageCode() === null)
                $form->getProjectI18n()->setLanguageCode(
                    $request->getContext()->getInitParameter(_Core::DEFAULT_LANGUAGE)
                );

        }

        return $mapping->findForward("success");

    }

}
?>